
import { defineAsyncComponent } from 'vue'
const getcomponents = {
    install(app:any) {
        //批量读取组件key  index * 匹配
       const  srcComponents = import.meta.glob('/src/components/Canvas/*/index.vue')
        
        //获取key
        const  keys = Object.keys(srcComponents)
       
        //获取所有值
       const  values = Object.values(srcComponents)
    
        //遍历所有注册组件 正则匹配替换
        keys.forEach((key, index) => {//index文件
            const ComponentsName = key.replace(/(\/src\/components\/Canvas\/)([a-zA-Z]+)(\/index\.vue)/, '$2')
          
            const component:any = values[index]
            app.component(ComponentsName, defineAsyncComponent(component))
        })
        const componentsPropEmitssSrc=import.meta.glob('/src/components/Canvas/*/prop.vue');
        Object.keys(componentsPropEmitssSrc).forEach((key,index)=>{//prop.vue文件
           const PropsCmn=key.replace(/(\/src\/components\/Canvas\/)([a-zA-Z]+)(\/prop\.vue)/, '$2Prop');
           const component:any=Object.values(componentsPropEmitssSrc)[index]
            app.component(PropsCmn,defineAsyncComponent(component))

        })
    }
}
export default getcomponents
